package com.butnet.myframe.hql.query;

import java.util.LinkedList;
import java.util.List;

public class OrderBys {
	private List<OrderBy> orders = new LinkedList<OrderBy>();
	private String objAsName = null;
	
	public OrderBys() {}
	public OrderBys(OrderBy ... ors) {
		for(OrderBy or : ors)
			appendOrderBy(or);
	}
	
	public OrderBys appendOrderBy(OrderBy ob){
		orders.add(ob);
		return this;
	}
	@Override
	public String toString(){
		if(orders.size()==0)return "";
		StringBuffer str = new StringBuffer();
		str.append(" ORDER BY ");
		OrderBy b = null;
		for(int i=0;i<orders.size();i++) {
			b = orders.get(i);
			b.setObjAsName(objAsName);
			str.append(b);
			if(i!=orders.size()-1)
				str.append(", ");
		}
		return str.toString();
	}
	public void setObjAsName(String asName) {
		objAsName = asName;
	}
	public String getObjAsName() {
		return objAsName;
	}
}
